<?php


namespace App\Http\Controllers;


use App\Models\ClassAndGradeTime;
use App\Models\SchoolClassAndGrade;
use Illuminate\Http\Request;
use Illuminate\Support\Facades\DB;

class ApiController extends Controller
{
    public function get_class_and_grade_by_club(Request $request)
    {
        $clubId = $request->get('q');
        return SchoolClassAndGrade::query()
            ->leftJoin('club','club.id','=','school_class_and_grade.club_id')
            ->where('club_id', $clubId)->get(['school_class_and_grade.id', DB::raw('CONCAT(club_name,"  ",grade,class_name) as text')]);
    }

    public function get_class_and_grade_by_school(Request $request)
    {
        $schoolId = $request->get('q');
        return SchoolClassAndGrade::query()
            ->leftJoin('school','school.id','=','school_class_and_grade.school_id')
            ->where('school_id', $schoolId)->get(['school_class_and_grade.id', DB::raw('CONCAT(school_name,"  ",grade,class_name) as text')]);
    }


    public function get_class_and_grade_time(Request $request)
    {
        $classId = $request->get('q');

        return ClassAndGradeTime::query()->where('class_and_grade_id',$classId)->get(['id',DB::raw('CONCAT(week_text,":",start_time,"-",end_time) as text')]);
    }
}
